/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package org.latestbit.smartobjects;

import org.latestbit.smartobjects.exceptions.*;
import org.latestbit.smartobjects.network.ConnectionHandler;
import org.latestbit.smartobjects.network.IEndpointLocation;

/**
 * Interface provides network access to remote smart object. 
 * Base interface for all network proxy client stubs.
 * @author abdulla-a
 *
 */
public interface IRemoteSmartObject extends ISmartObject {
	
	/**
	 * Resolves a remote smart object for specified endpoint location (network addresses)
	 * @param bus instance of ISmartBus 
	 * @param location Endpoint location / network address (addresses)
	 * @throws SmartBusSystemException
	 * @throws InterruptedException
	 */
	void resolve(ISmartBus bus, IEndpointLocation location) throws SmartBusSystemException, InterruptedException;
	
	/**
	 * Resolves a remote smart object for specified already created another remote smart object instance
	 * @param baseClient Already resolved remote smart object
	 * @throws SmartBusSystemException
	 */
	void resolve( IRemoteSmartObject baseClient) throws SmartBusSystemException;
	
	/**
	 * Resolves a remote smart object for specified already created 
	 * another remote smart object or skeleton instance and incoming request connection. 
	 * @param baseObject Already resolved remote smart object or published server skeleton
	 * @param connectionHandler Connection handler for incoming client request
	 * @throws SmartBusSystemException
	 */
	void resolve( ISmartObject baseObject, ConnectionHandler connectionHandler ) throws SmartBusSystemException;
	
	/**
	 * Sets RequestContext for all outgoing calls of operations. 
	 * @param context new instance of request context with parameters
	 */
	public void setDefaultRequestContext(RequestContext context);
	
	/**
	 * Gets RequestContext used for all outgoing calls of operations.
	 * @return current RequestContext
	 */
	public RequestContext getDefaultRequestContext();
	
	/**
	 * Adds the notification listener for network/logical availability for this remote smart object
	 * @param <T> All generated client stubs with IRemoteSmartObject as base interface
	 * @param listener Listener implementation
	 */
	public <T extends IRemoteSmartObject> void addAvailabilityListener(IRemoteSmartObjectAvailabilityListener<T> listener);

	/**
	 * Deletes notification listener for network/logical availability for this remote smart object
	 * @param <T> All generated client stubs with IRemoteSmartObject as base interface
	 * @param listener Listener implementation
	 */
	public <T extends IRemoteSmartObject> void delAvailabilityListener(IRemoteSmartObjectAvailabilityListener<T> listener);
	
	/**
	 * Checks network/logical availability
	 * @return true - is available to proceed operation calls, or false - if not
	 */
	public boolean isAvailable();

}
